$(document).ready(function(){
	$("#modifyUser").val(username);	
	//下拉初始化
	InitchannelId();
	$("input[type=file]").change(function(){ 		
		ajaxfileuploadUtil(this,"popChannel");
	});
	
	var src = tl_config.his_url;
	var i = src.indexOf('?');
	
	if(i!=-1){
		var id = src.substring(i+4);
        $.ajax({
        	url:server_url+'/rest/PopChannel/selectPopChannelById.do?ran='+Math.random()+ '&token=' + token,
        	type:'get',
        	data:{id:id},
        	success:function(data){
        		if(data.retCode=='1003'){
					localStorage.clear();
					window.location.href="login.do";
					return;
				}
        		if(data.retCode==='0000'){        		
        			$("#id").val(data.data.id);
        			$("#channelId").val(data.data.channelId);
        			$("#type").val(data.data.type);
        			$("#positions").val(data.data.positions);  
        			$("#supplyProductId").val(data.data.supplyProductId);
        			$("#picName").val(data.data.picName);  
        			$("#picLink").val(data.data.picLink);
        			$("#sort").val(data.data.sort);  
        			$("[name=picUrl]").val(data.data.picUrl);
        			$("#imgPath").attr("src",data.data.picUrl);         			
        		}
        	}
        });
	}
});

//初始化下拉列表
function InitchannelId()
{
	
	$.ajax({
		url:server_url+'/rest/Channel/selectChannel.do?ran='+Math.random()+"&token="+token,
		type:'get',
		success:function(data){
			if(data.retCode=="0000"){
				for(var i=0;i<data.data.length;i++){
					$("#channelId").append("<option value='"+data.data[i].id+"'>"+data.data[i].channelName+"</option>");
				}
			}
			else{
				easyDialog.open({
					  container : {
						  header : '提示',
					      content : data.retMsg
					  },
					  autoClose : 2000
					});				
			} 			
		}
	});	
}

function back(){	
	var url="getPopChannelListPage.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}

function submitCommit(){
	$.ajax({
		url:server_url+'/rest/PopChannel/PopChannelEdit.do?ran='+Math.random()+ '&token=' + token,
		type:'post',
		data:$("#fromPopChannelEdit").serialize(),
		success:function(data){
			easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose: 2000});
			back();
		}
	});
}
